package day24;

import java.io.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

public class Demo6 {
    static List<StudentInfo> students = new ArrayList<>();
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Scanner sc = new Scanner(System.in);
        System.out.println("1.序列化 2.反序列化");
        int a = sc.nextInt();
        if(a == 1){
            output();
        }else if(a == 2){
            input();
        }
    }

    static void input() throws IOException, ClassNotFoundException {
        FileInputStream fis = new FileInputStream("d://a//abcd.txt");
        ObjectInputStream ois = new ObjectInputStream(fis);
        StudentInfo s2 = (StudentInfo)ois.readObject();
        System.out.println(s2);
        ois.close();
        fis.close();
    }

    static void output() throws IOException {
        StudentInfo s1 = new StudentInfo(4,"男","100");
        students.add(s1);
        FileOutputStream fos = new FileOutputStream("d://a//abcd.txt");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(s1);
        oos.close();
        fos.close();
    }
}
